var pageParams;
$(function () {
    pageParams=$$.getQueryString();
    //渲染表格
    var columns = cacheDataList.columnsInit();
    var table = cacheDataList.gridInit(columns);
   // var datas = cacheDataList.dataInit();
   // $("#cacheDataTable").bootstrapTable("append",datas);
})
;(function(undefined) {
    "use strict"
    var _global;

    function result(args,fn){
        var argsArr = Array.prototype.slice.call(args);
        if(argsArr.length > 0){
            return argsArr.reduce(fn);
        } else {
            return 0;
        }
    }
    var cacheDataList = {
        columnsInit:function(){
            return  [{
                field: 'pk',
                title: '序号',
                width: '2%',
                align: 'center',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            }, {
                field: 'rs',
                title: '引用开始时间',
                width: '10%',
                align: 'center',
                formatter: function (value, row, index) {
                    value=value.substring(value.indexOf("_")+1);
                    return format(parse(value, 'yyyyMMddHHmmss'), 'yyyy-MM-dd HH:mm:ss');

                }


            }, {
                field: 're',
                title: '引用结束时间',
                width: '10%',
                align: 'center',
                formatter: function (value, row, index) {
                    value=value.substring(value.indexOf("_")+1);
                    return format(parse(value, 'yyyyMMddHHmmss'), 'yyyy-MM-dd HH:mm:ss');
                }

            }, {
                field: 'ts',
                title: '开始时间',
                width: '10%',
                align: 'center',
                formatter: function (value, row, index) {

                    return format(parse(value, 'yyyyMMddHHmmss'), 'yyyy-MM-dd HH:mm:ss');

                }


            }, {
                field: 'te',
                title: '结束时间',
                width: '10%',
                align: 'center',
                formatter: function (value, row, index) {

                    return format(parse(value, 'yyyyMMddHHmmss'), 'yyyy-MM-dd HH:mm:ss');
                }

            }, {
                field: 'so',
                title: '开始原始值'
            }, {
                field: 'sv',
                title: '开始计算值'
            }, {
                field: 'eo',
                title: '结束原始值'
            }, {
                field: 'ev',
                title: '结束计算值'
            }, {
                field: 'bv',
                title: '本次值',
                formatter: function (value, row, index) {
                    console.log(index);

                    // row.setAttribute("style","background: #fedd7c;");
                    return value;
                }
            }, {
                field: 'st',
                title: '创建时间',
                formatter: function (value, row, index) {

                    return format(parse(value, 'yyyyMMddHHmmss'), 'yyyy-MM-dd HH:mm:ss');
                }
            }]
        },
        gridInit:function(columns){
            return $("#cacheDataTable").bootstrapTable({

                columns: columns,
                classes: 'table table-hover qxttable',
                method: 'post',
                sortable: true,
                pagination: false,
                url: $$.restServerUrl + '/bootstrap/basegrid/SamplingLjBusiness/listData',
                cache: false,
                striped: true,
                onlyInfoPagination: true,
                pageList: [10, 20, 50, 100],
                showColumns: false,
                showRefresh: false,
                search: false,
                clickToSelect: true,
                dataField: "rows",
                pageNumber: 1,
                showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
                singleSelect: false,
                queryParamsType: "page",
                sidePagination: "server",
                undefinedText: '-',
                contentType: "application/x-www-form-urlencoded",
                pageSize: 10,
                idField: 'pk',
                toolbarAlign: 'right',
                queryParams: function queryParams(params) {   //设置查询参数
                    var pk=pageParams.pk;
                    var deviceCode=pk.substring(0,pk.indexOf("_"));
                    var dateStr=pk.substring(pk.indexOf("_")+1);
                    var start_time = dateStr;
                    var endDate=parse(start_time,'yyyyMMdd');
                    endDate.setDate(endDate.getDate()+1);
                    var end_time =format(endDate,'yyyyMMdd');
                    var args = {};
                    args.iotCode = deviceCode;
                    args.tableName='iot_base';

                    args.startTime = start_time;  //20170918010000 ;
                    args.endTime = end_time;

                    args.isPage=2;
                    //args.order=orderStr;
                    var paramStr=JSON.stringify(args);

                    //alert(params.pageNumber+":"+params.pageSize);
                    //alert(orderStr);
                    var param = {
                        params:paramStr
                    };
                    return param;
                }




            })

        },
        dataInit:function(){
            return  [{
                od: 1,
                pk: 'DLC0001',
                pwd: 'DLC0001'
            }, {
                pk: 'DLC0001',
                pwd: 'DLC0001',
            },{
                od: 3,
                pk: 'DLC0001',
                pwd: 'DLC0001',
            },{
                od: 4,
                pk: 'DLC0001',
                pwd: 'DLC0001',
            },{
                od: 5,
                pk: 'DLC0001',
                pwd: 'DLC0001',
            },{
                od: 6,
                pk: 'DLC0001',
                pwd: 'DLC0001',
            },{
                od: 7,
                pk: 'DLC0001',
                pwd: 'DLC0001',
            },{
                od: 8,
                pk: 'DLC0001',
                pwd: 'DLC0001',
            },{
                od: 9,
                pk: 'DLC0001',
                pwd: 'DLC0001',
            },{
                od: 10,
                pk: 'DLC0001',
                pwd: 'DLC0001',
            },{
                od: 11,
                pk: 'DLC0001',
                pwd: 'DLC0001',
            },{
                od: 12,
                pk: 'DLC0001',
                pwd: 'DLC0001',
            },{
                od: 13,
                pk: 'DLC0001',
                pwd: 'DLC0001',
            }]
        }
    }

    // 将插件对象暴露给全局对象
    _global = (function(){ return this || (0, eval)('this'); }());
    if (typeof module !== "undefined" && module.exports) {
        module.exports = cacheDataList;
    } else if (typeof define === "function" && define.amd) {
        define(function(){return cacheDataList;});
    } else {
        !('plugin' in _global) && (_global.cacheDataList = cacheDataList);
    }
}());